给定两个字符串 S 和 T ,判断 S 是否是 T 的子序列。
即是否可以从 T 删除一些字符转换成 S。
数据范围: , ,保证字符串中仅含有小写字母
"nowcoder","nowcoder"
true
"nower","nowcoder"
true
"nowef","nowcoder"
false
from operator import index # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param S string字符串 # @param T string字符串 # @return bool布尔型 # class Solution: def isSubsequence(self , S: str, T: str) -> bool: # write code here index = 0 for s in T: if S[index] == s: index += 1 if index == len(S): return True if index == len(S): return True return False
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param S string字符串 # @param T string字符串 # @return bool布尔型 # class Solution: def isSubsequence(self , S: str, T: str) -> bool: # write code here import re pattern = "" for ch in S: pattern += ch + "[a-z]*" if re.search(pattern, T) == None: return False return True